package com.runa.monitor.platinterface.extend.nb.mqtt;

import com.alibaba.fastjson.JSON;
import com.runa.monitor.platinterface.extend.nb.service.NbPlantService;
import com.runa.monitor.platinterface.extend.nb.utils.MqttSetUtils;
import com.runa.monitor.platinterface.extend.nb.vo.ReportDataBaseVo;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MqttUpDataQueue implements Runnable {
    private String appKey;
    private String appSecret;
    private NbPlantService mqttService;
    private ReportDataBaseVo reportDataBaseVo;

    public MqttUpDataQueue(String appKey, String appSecret, NbPlantService mqttService, ReportDataBaseVo reportDataBaseVo) {
        this.appKey = appKey;
        this.appSecret = appSecret;
        this.mqttService = mqttService;
        this.reportDataBaseVo = reportDataBaseVo;
    }


    @Override
    public void run() {
        log.info("mqtt监听到电信消息---"+ JSON.toJSONString(reportDataBaseVo));
        if (reportDataBaseVo == null) {
            return;
        }
//        SendCmdConfigVo sendCmdConfigVo = new SendCmdConfigVo();
//        sendCmdConfigVo.setDeviceId(reportDataBaseVo.getDeviceId());
//        sendCmdConfigVo.setProductId(reportDataBaseVo.getProductId());
//        sendCmdConfigVo.setAppKey(appKey);
//        sendCmdConfigVo.setAppSecret(appSecret);
        String productId = reportDataBaseVo.getProductId();
        if (MqttSetUtils.PANEL_PRODUCT_ID.equals(productId)) {
//            sendCmdConfigVo.setMasterKey(MqttSetUtils.PANEL_MASTER_KEY);
//            sendCmdConfigVo.setTipMessage("nb-iot温度面板");
            mqttService.receiveAEP_Temperature( reportDataBaseVo, "RUNA");
        }else if (MqttSetUtils.RU_PANEL_PRODUCT_ID.equals(productId)) {
//            sendCmdConfigVo.setMasterKey(MqttSetUtils.RU_PANEL_MASTER_KEY);
//            sendCmdConfigVo.setTipMessage("nb-iot-ru温度面板");
            mqttService.receiveAEP_RU_Temperature( reportDataBaseVo);
        } else if (MqttSetUtils.BUILD_METER_PRODUCT_ID.equals(productId)) {
//            sendCmdConfigVo.setMasterKey(MqttSetUtils.BUILD_METER_MASTER_KEY);
//            sendCmdConfigVo.setTipMessage("nb-iot楼表");
            mqttService.receiveAEP_BuildMeter( reportDataBaseVo);
        } else if (MqttSetUtils.BUILD_VALVE_PRODUCT_ID.equals(productId)) {
//            sendCmdConfigVo.setMasterKey(MqttSetUtils.BUILD_VALVE_MASTER_KEY);
//            sendCmdConfigVo.setTipMessage("nb-iot楼阀");
            mqttService.receiveAEP_BuildValve( reportDataBaseVo);
        } else if (MqttSetUtils.TEMPERATURE_PRESSURE_PRODUCT_ID.equals(productId)) {
//            sendCmdConfigVo.setMasterKey(MqttSetUtils.TEMPERATURE_PRESSURE_MASTER_KEY);
//            sendCmdConfigVo.setTipMessage("nb-iot温压检测仪");
            mqttService.receiveAEP_Temperaturepressure( reportDataBaseVo);
        } else {
            log.error("此电信mqtt消息无此NB产品号对应---"+JSON.toJSONString(reportDataBaseVo));
        }
    }
}
